<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.key" placeholder="搜索拍品" style="width: 300px;margin-right: 10px;" @keyup.enter.native="handleFilter">
        <el-button slot="append" icon="el-icon-search" @click="handleFilter" />
      </el-input>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
    >
      <el-table-column align="center" label="ID" prop="id" width="100" />
      <el-table-column align="center" label="图录号" prop="gnumber" width="100" />
      <el-table-column show-overflow-tooltip align="center" label="拍品名称" prop="gname" width="300" />
      <el-table-column show-overflow-tooltip align="center" label="专场" prop="lot_name" width="240" />
      <el-table-column align="center" label="委托人" prop="bnumer" width="100" />
      <el-table-column align="center" label="委托价格" width="140">
        <template slot-scope="scope"><b style="color: green">{{ scope.row.bprice ? '￥' + toThousands(scope.row.bprice) : '-' }}</b></template>
      </el-table-column>
    </el-table>

    <div v-show="total > 0" class="pagination-container">
      <el-pagination background :current-page="listQuery.page" :page-sizes="[15, 20, 30]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
  </div>
</template>

<script>
import { getConsigns } from '@/api/goods'
import { toThousands } from '@/utils'
export default {
  data () {
    return {
      listQuery: {
        key: '',
        page: 1,
        limit: 15
      },
      list: [],
      total: 0,
      listLoading: true
    }
  },
  created () {
    this.fetchData()
  },
  methods: {
    fetchData () {
      this.listLoading = true
      getConsigns(this.listQuery).then(res => {
        this.list = res.data.list
        this.total = res.data.total
        this.listLoading = false
      }).catch(err => {
        console.log(err)
        this.listLoading = false
      })
    },
    handleFilter () {
      this.listQuery.page = 1
      this.fetchData()
    },
    handleSizeChange (val) {
      this.listQuery.limit = val
      this.fetchData()
    },
    handleCurrentChange (val) {
      this.listQuery.page = val
      this.fetchData()
    },
    toThousands
  }
}
</script>

<style lang="scss">
.el-table {
  width: fit-content;
  margin-bottom: 20px;
  .ing-row {
    background: rgb(243, 218, 210);
  }
}
</style>
